class MovingAverage
{
public:
    MovingAverage(int size)
    {
        this->q = vector<int>(size);
        this->sum = 0;
        this->cur = 0;
        this->size = size;
        this->count = 0;
    }

    double next(int val)
    {
        sum -= q[cur];
        sum += val;
        q[cur] = val;
        cur = (cur + 1) % size;
        if (count < size)
        {
            ++count;
        }
        return 1.0 * sum / count;
    }

private:
    vector<int> q;
    int sum;
    int cur;
    int size;
    int count;
};

/**
 * Your MovingAverage object will be instantiated and called as such:
 * MovingAverage* obj = new MovingAverage(size);
 * double param_1 = obj->next(val);
 */